var { Plot } = require("../Plot.js")

var { initPointList } = require("../points");
var { Point } = require("../Point");

var canvasMv = require("../nodeSet/canvasMv")

// @ts-ignore
var plot = new Plot(document.getElementById("myCanvas"));

var list = initPointList(25);
var lines = getLines(list)


function test1() {
	lines.forEach((indexs, index) => {
		plot.drawDot(list[index]);
		indexs.forEach(index2 => {
			plot.line(list[index], list[index2]);
		});
	});
}

/**
 * @param {any[]} plots
 */
function getLines(plots) {
	var arr = new Array(plots.length)

	plots.forEach((v, index) => {
		v.index = index
	})

	plots.forEach((v, index0) => {
		var lens = plots.map((v1, index) => {
			v1.len = Point.len(v, v1)
			return v1
		})
		lens.sort((v1, v2) => {
			return v1.len > v2.len ? 1 : -1
		});
		arr[index0]=  lens.map(v => v.index).slice(0, 2)
	})
	return arr
}

function test2() {
	plot.clean()
	for (let index = 0,len = list.length; index < len; index++) {
		plot.drawDot(list[index]);
		for (let index1 = 0,len = list.length; index1 < len; index1++) {
			var color = (index + index1) % 2 == 1 ? 'red' : 'green'
			plot.line(list[index], list[index1], color);	
		}
	}
}

canvasMv(plot.container, list, test2)

test2()